//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<math_win32.h>
///	@path	~/src/lib/math/
///	@date	2008/05/24
///	@desc	Helper functions for win32 API (especially for GDI).

#pragma once

#include "xeres.h"

#include "lib/math/pair.h"
#include "lib/math/vector.h"
#include "lib/math/color.h"
#include "lib/math/rect.h"

namespace xeres {

	/*! 
		\name Win32 API helper functions
		@{
	*/

	/*!
		\brief		Calculate width from a RECT.
	*/
	static int RectWidth( const RECT& rc )
	{
		return rc.right - rc.left;
	}

	/*!
		\brief		Calculate height from a RECT.
	*/
	static int RectHeight( const RECT& rc )
	{
		return rc.bottom - rc.top;
	}

	/*! 
		\brief		Calculate distance between 2 points.
	*/
	static float PointDistance( const POINT& a , const POINT& b )
	{
		POINT diff;
		diff.x = a.x - b.x;
		diff.y = a.y - b.y;
		return sqrtf( (float)(diff.x*diff.x) + (float)(diff.y*diff.y) );
	}

	/*!
		\brief		Rect to RECT structure.
	*/
	static const RECT& toRECT( const Rect<int>& rect )
	{
		return *(const RECT*)&rect;
	}

	/*!
		\brief		Pair to POINT structure.
	*/
	static const POINT& toRECT( const Pair<int>& pt )
	{
		return *(const POINT*)&pt;
	}

#ifdef _GDIPLUS_H

	/*!
		\brief		Rect to Gdiplus::Rect structure.
	*/
	static Gdiplus::Rect toRect( const Rect<int>& rect )
	{
		return Gdiplus::Rect( rect.left() , rect.top() , rect.width() , rect.height() );
	}

	/*!
		\brief		Rect to Gdiplus::RectF structure.
	*/
	static Gdiplus::RectF toRectF( const Rect<int>& rect )
	{
		return Gdiplus::RectF( (Gdiplus::REAL)rect.left() , (Gdiplus::REAL)rect.top() , (Gdiplus::REAL)rect.width() , (Gdiplus::REAL)rect.height() );
	}

	/*!
		\brief		Pair to Gdiplus::Point structure.
	*/
	static Gdiplus::Point toPoint( const Pair<int>& pt )
	{
		return Gdiplus::Point( pt.x , pt.y );
	}

	/*!
		\brief		Pair to Gdiplus::PointF structure.
	*/
	static Gdiplus::PointF toPointF( const Pair<int>& pt )
	{
		return Gdiplus::PointF( (Gdiplus::REAL)pt.x , (Gdiplus::REAL)pt.y );
	}

#endif /*_GDIPLUS_H*/

	/*!
		@}
	*/

} // namespace xeres
